package com.tms.warehouse;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tms.warehouse.entity.Series;

@SuppressWarnings("serial")
public class SeriesController extends BaseController {

	private static final String PARAMETER_ID = "entityId";
	private static final String PARAMETER_NAME = "name";

	@Override
	protected String doListAction(HttpServletRequest req,
			HttpServletResponse resp) {

		List<Series> seriesList = Warehouse.getAllSeries();
		req.setAttribute("entities", seriesList);
		return "./series.jsp";
	}

	@Override
	protected String doCreateAction(HttpServletRequest req,
			HttpServletResponse resp) {

		return "./series.jsp";
	}

	@Override
	protected String doEditAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);
		Series series = Warehouse.findSeriesById(entityId);
		req.setAttribute("entity", series);
		return "./series.jsp";
	}

	@Override
	protected String doDeleteAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);
		Warehouse.deleteSeries(entityId);
		return TARGET_SELF;
	}

	@Override
	protected String doSaveAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);
		String name = req.getParameter(PARAMETER_NAME);
		Warehouse.persistSeries(entityId, name);
		return TARGET_SELF;
	}

}
